package com.ruyuan.common.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xx
 */
public class Features implements Serializable {
    private static final long serialVersionUID = 7586055641671203820L;

    private Map<String, String> featureMap = new HashMap<>();

    public static Features of() {
        return new Features();
    }

    public static Features of(String str) {
        Features features = new Features();
        Map<String, String> featureMap = JSON.parseObject(str, new TypeReference<Map<String, String>>(){});
        features.featureMap.putAll(featureMap);
        return features;
    }

    public String getFeature(String key) {
        return featureMap.get(key);
    }

    public void addFeature(String key, String value) {
        featureMap.put(key, value);
    }

    public boolean isEmpty() {
        return featureMap.isEmpty();
    }

    @Override
    public String toString() {
        return JSON.toJSONString(featureMap);
    }

}
